/////////////////////////////////////////////////////
//	File:		CreditsState.cpp
//	Class:		SGP
//	Updated:	3/6/2012
//	Author:		Roc Myers
//	Purpose:	To contain all Credits related code
/////////////////////////////////////////////////////

#include "MainMenuState.h"
#include "Game.h"
#include "CreditsState.h"
#include "SGD Wrappers\CSGD_TextureManager.h"
#include "SGD Wrappers\CSGD_DirectInput.h"
#include "SGD Wrappers\CSGD_XAudio2.h"
CreditsState* CreditsState::pInstance = nullptr;


CreditsState::CreditsState(void)
{
	MusicID = -1;
	TitleID = -1;
	FontID = -1;
	textPos = 0.0f;
}

CreditsState& CreditsState::operator=(const CreditsState&)
{
	return *this;
}

void CreditsState::DeleteInstance()
{
	if(pInstance != nullptr)
	{
		delete pInstance;
		pInstance = nullptr;
	}
}

CreditsState::~CreditsState(void)
{
}

CreditsState* CreditsState::GetInstance(void)
{
	if(pInstance == nullptr)
		pInstance = new CreditsState();

	return pInstance;
}

void CreditsState::Enter(void)
{
	// Load in assets
	FontID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/LARPFont.png"));
	MusicID = CSGD_XAudio2::GetInstance()->MusicLoadSong(_T("resource/Bohemian Rhapsody.xwm"));
	TitleID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/logo_game.png"));
	textPos = 3000;
	Font.Initialize(FontID,"LARPFont.fnt");

	CSGD_XAudio2::GetInstance()->MusicPlaySong(MusicID, true);

	// Set up sound
	CSGD_XAudio2::GetInstance()->SFXSetMasterVolume(Game::GetInstance()->SfxVol);
	CSGD_XAudio2::GetInstance()->MusicSetMasterVolume(Game::GetInstance()->BgmVol);
	CSGD_XAudio2::GetInstance()->MusicSetSongPan(MusicID, Game::GetInstance()->Pan);

	arcadeEnter = false;
	arcadeEscape = false;
	arcadeUp = false;
	arcadeDown = false;
	arcadeLeft = false;
	arcadeRight = false;
	arcadeBackspace = false;
	arcadeShift = false;
	arcadePlus = false;
	arcadeMinus = false;
	arcadeP = false;

}

bool CreditsState::Input(void)
{
	ArcadeInput();

	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_ESCAPE)||arcadeEscape)
		Game::GetInstance()->ChangeState(MainMenuState::GetInstance());

	return true;
}

void CreditsState::Update(float fElapsedTime)
{
	textPos -= (50 * fElapsedTime);
	CSGD_XAudio2::GetInstance()->Update();

	if(textPos <= -700)
		textPos = 3000;
	//	Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
}

void CreditsState::Render(void)
{
	//Font.Print("LARP Arena", 20, textPos - 1300, 3.0f);
	Font.Print("Press Esc To Exit", (int)(Game::GetInstance()->GetWinWidth()- (Game::GetInstance()->GetWinWidth()*0.27)), (int)(Game::GetInstance()->GetWinHeight()*0.93), 1.0f, 255,50,100);
	CSGD_TextureManager::GetInstance()->Draw(TitleID,140,(int)textPos - 2275,1.0f,1.0f,nullptr,0.0f,0.0f,0.0f,D3DCOLOR_XRGB(255,255,255));
	Font.Print("Created By: Why Not Zoidberg?", 50, (int)textPos - 1850, 2.0f);

	Font.Print("Executive Producer", 20, (int)textPos - 1750, 3.0f);
	Font.Print("John O'Leske", 40, (int)textPos - 1650, 2.0f);

	Font.Print("Associate Producers:", 20, (int)textPos - 1550, 3.0f);
	Font.Print("Shawn Paris", 20, (int)textPos - 1450, 2.0f);
	Font.Print("Sean Hathaway", 20, (int)textPos - 1400, 2.0f);
	Font.Print("Rob Martinez", 20, (int)textPos - 1350, 2.0f);

	Font.Print("Lead Programmer:", 20, (int)textPos - 1250, 3.0f);
	Font.Print("Charles Meade", 20, (int)textPos - 1150, 2.0f);

	Font.Print("Programmers:", 20, (int)textPos - 1000, 3.0f);
	Font.Print("Justin Maza", 20, (int)textPos - 900, 2.0f);
	Font.Print("Mike Barbato", 20, (int)textPos - 850, 2.0f);
	Font.Print("Roc Myers", 20, (int)textPos - 800, 2.0f);

	Font.Print("Art and Graphics", 20, (int)textPos - 700, 3.0f);
	Font.Print("Maher Sagrillo", 20, (int)textPos - 600, 2.0f);
	Font.Print("Chris Jahosky", 20, (int)textPos - 550, 2.0f);

	Font.Print("Sound Engineer", 20, (int)textPos - 450, 3.0f);
	Font.Print("Jesse Williams", 20, (int)textPos - 350, 2.0f);

	Font.Print("Voice Acting", 20, (int)textPos - 250, 3.0f);
	Font.Print("Mike Barbato - Internet Wizard", 20, (int)textPos - 150, 2.0f);
	Font.Print("Justin Maza - Obvious Rogue", 20, (int)textPos - 100, 2.0f);
	Font.Print("Roc Myers - G. Archer/Announcer 1", 20, (int)textPos - 50, 2.0f);
	Font.Print("Charles Meade - C. Knight/Announcer 2", 20, (int)textPos, 2.0f);

	Font.Print("Title Music", 20, (int)textPos+100, 3.0f);
	Font.Print("Guilds at War, by Jeremy Soule", 20, (int)textPos+200, 2.0f);

	Font.Print("Battle Music", 20, (int)textPos + 300, 3.0f);
	Font.Print("Trisection, by Hitoshi Sakimoto", 20, (int)textPos + 400, 2.0f);

	Font.Print("Credits Theme", 20, (int)textPos + 500, 3.0f);
	Font.Print("Bohemian Rhapsody, by Queen", 20, (int)textPos + 600, 2.0f);

	Font.Print("Thanks for Playing!", 50, (int)textPos + 800, 3.0f);

	//Font.Print("Attack and Abilities", 20, (int)textPos - 825, 2.0f);
	//Font.Print("CJ Meade", 20, (int)textPos - 750, 1.0f);
	//
	//Font.Print("Dice roll System", 20, (int)textPos - 650, 2.0f);
	//Font.Print("Mike Barbato", 20, (int)textPos - 575, 1.0f);
	//
	//Font.Print("Stat System", 20, (int)textPos - 475, 2.0f);
	//Font.Print("Roc Myers", 20, (int)textPos - 400, 1.0f);
	//
	//Font.Print("Leveling System", 20, (int)textPos - 300, 2.0f);
	//Font.Print("Justin Maza", 20, (int)textPos - 225, 1.0f);
	//
	//Font.Print("Menu Systems", 20, (int)textPos - 1175, 2.0f);
	//Font.Print("Roc Myers", 20, (int)textPos - 1100, 1.0f);

}

void CreditsState::Exit(void)
{
	if(MusicID != -1)
	{
		if(CSGD_XAudio2::GetInstance()->MusicIsSongPlaying(MusicID))
			CSGD_XAudio2::GetInstance()->MusicStopSong(MusicID);

		CSGD_XAudio2::GetInstance()->MusicUnloadSong(MusicID);

		MusicID = -1;

	}

	
	if(FontID != -1)
	{
		CSGD_TextureManager::GetInstance()->UnloadTexture(FontID);
		FontID = -1;
	}

	DeleteInstance();
}

void CreditsState::ArcadeInput()
{
	arcadeEnter = false;
	arcadeEscape = false;
	arcadeUp = false;
	arcadeDown = false;
	arcadeLeft = false;
	arcadeRight = false;
	arcadeBackspace = false;
	arcadeShift = false;
	arcadePlus = false;
	arcadeMinus = false;
	arcadeP = false;

	CSGD_DirectInput * di = CSGD_DirectInput::GetInstance();

	if(di->JoystickGetLStickDirPressed(DIR_UP,0))
	{
		arcadeUp = true;
	}

	if(di->JoystickGetLStickDirPressed(DIR_DOWN,0))
	{
		arcadeDown = true;
	}

	if(di->JoystickGetLStickDirPressed(DIR_LEFT,0))
	{
		arcadeLeft = true;
	}

	if(di->JoystickGetLStickDirPressed(DIR_RIGHT,0))
	{
		arcadeRight = true;
	}

	if(di->JoystickButtonPressed(0,0))
	{
		arcadeEnter = true;
	}

	if(di->JoystickButtonPressed(1,0))
	{
		arcadeBackspace = true;
	}

	if(di->JoystickButtonPressed(2,0))
	{
		arcadeP = true;
	}

	if(di->JoystickButtonPressed(3,0))
	{
		arcadeShift = true;
	}

	if(di->JoystickButtonPressed(4,0))
	{
		arcadePlus = true;
	}

	if(di->JoystickButtonPressed(5,0))
	{
		arcadeMinus = true;
	}

	if(di->JoystickButtonPressed(6,0))
	{
		arcadeEscape = true;
	}
}

